<?php

namespace app\index\validate;

use think\Validate;

class User extends Validate
{
    protected $rule = [
    	'captcha'=>'require|captcha',
    	'agreement'  =>  'require',
        'nickname'  =>  'require|min:5|max:18|unique:user',
        'phone'  =>  'require|regex:1\d{10}|number|unique:user',
        'password'  =>  'require|min:6',
        'repassword'  =>  'require|confirm:password',
        'vercode'=>'require|checkcode'
    ];

    protected $message  =   [
        'phone.unique' => '手机已存在',    
        'phone.regex' => '手机格式不对',    
        'agreement.require' => '服务条款必须同意',    
        'repassword.confirm' => '两次密码不一致',    
    ];

    protected $scene = [
        'login'  =>  ['captcha'],
        'save'  =>  ['phone','nickname'],
        'send'  =>  ['phone'],
    ];

    public function checkcode($value,$rule,$data)
    {
        $msginfo = session('msginfo');

        if($msginfo){

            if($msginfo['code']==$value && $msginfo['phone']==$data['phone'] && time()-$msginfo['create_time']<900){
                return true;
            }

        }
        return "手机验证错误";
    }

}
